public class Solution {
    //奇偶排序
    public int[] sortArrayByParity(int[] nums) {
        int left = 0;
        int right = nums.length-1;
        while(left < right) {
            if(left >= right) {
                break;
            }
            //找到左边的奇数
            while(left < right && nums[left] % 2 != 0) {
                left++;
            }
            //找到右边的偶数
            while(left < right && nums[right] % 2 == 0) {
                right--;
            }
            //交换位置
            int tmp = nums[left];
            nums[left] = nums[right];
            nums[right] = tmp;
        }
        return nums;
    }
}
